import mono_hlsb from "./wasm_mono_hmsb";
self.addEventListener('message', async (e) => {
  try {
    var data = e.data;
    switch (data.function) {
      case "drawCanvasData":
        self.postMessage({
          function: data.function,
          uuid: data.uuid,
          message: "Success",
          return: await mono_hlsb.drawCanvasData(data.data, data.imgWidth, data.imgHeight, data.scale, data.color, data.backgroundColor),
        });
        break;
      case "parseDataFromCanvas":
        self.postMessage({
          function: data.function,
          uuid: data.uuid,
          message: "Success",
          return: await mono_hlsb.parseDataFromCanvas(data.data, data.imgWidth, data.imgHeight, data.scale, data.color),
        });
        break;
      case "convertToGrayScale":
        self.postMessage({
          function: data.function,
          uuid: data.uuid,
          message: "Success",
          return: await mono_hlsb.convertToGrayScale(data.data),
        });
        break;
      case "convertToBlackWhite":
        self.postMessage({
          function: data.function,
          uuid: data.uuid,
          message: "Success",
          return: await mono_hlsb.convertToBlackWhite(data.data, data.grayThreshold),
        });
        break;
      case "convertToBlackWhiteDither":
        self.postMessage({
          function: data.function,
          uuid: data.uuid,
          message: "Success",
          return: await mono_hlsb.convertToBlackWhiteDither(data.data, data.imgWidth),
        });
        break;
      case "convertToBlackWhiteFloydSteinberg":
        self.postMessage({
          function: data.function,
          uuid: data.uuid,
          message: "Success",
          return: await mono_hlsb.convertToBlackWhiteFloydSteinberg(data.data, data.imgWidth),
        });
        break;
      default:
        self.postMessage({
          function: data.function,
          uuid: data.uuid,
          message: 'Unknown command: ' + data.function,
        });
    };
  } catch (err) {
    console.error(err);
  }
}, false);